# Use an official Maven image to build the application
FROM maven:3.8.5-openjdk-17-slim AS build

# Define author information
LABEL maintainer="dx<xxx@qq.com>"

# Set the working directory inside the container
WORKDIR /app

# Copy the pom.xml and local dependencies first to leverage caching
COPY pom.xml ./
COPY lib /app/lib

# Install the local JAR files
RUN mvn install:install-file -Dfile=/app/lib/kfpt-sdk-1.0.0.jar -DgroupId=open.yundaex -DartifactId=kfpt-sdk -Dversion=1.0.0 -Dpackaging=jar
RUN mvn install:install-file -Dfile=/app/lib/jt-openapi-sdk-1.0.0.jar -DgroupId=com.yl -DartifactId=t-openapi-sdk -Dversion=1.0.0 -Dpackaging=jar
RUN mvn install:install-file -Dfile=/app/lib/SF-CSIM-EXPRESS-SDK-V2.1.7.jar -DgroupId=com.sf -DartifactId=SF-CSIM-EXPRESS-SDK -Dversion=2.1.7 -Dpackaging=jar
RUN mvn install:install-file -Dfile=/app/lib/lop-opensdk-support-1.0.28-SNAPSHOT.jar -DgroupId=com.jd.sdk -DartifactId=opensdk-support -Dversion=1.0.28 -Dpackaging=jar
RUN mvn install:install-file -Dfile=/app/lib/ECAP_3.0_20240729101852.jar -DgroupId=com.jd.sdk -DartifactId=ecap -Dversion=3.0.0 -Dpackaging=jar
RUN mvn install:install-file -Dfile=/app/lib/java-sdk-1.0-SNAPSHOT.jar -DgroupId=com.fdd -DartifactId=java-sdk -Dversion=1.0.0 -Dpackaging=jar

# Download project dependencies
# RUN mvn dependency:go-offline -B

# Copy the rest of the application code
COPY src ./src

# Build the application
RUN mvn clean package -DskipTests

# Use a minimal base image for the final stage
FROM openjdk:17-jdk-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the jar file from the build stage
COPY --from=build /app/target/elephant-0.0.1-SNAPSHOT.jar ./elephant.jar

# Expose the application port
EXPOSE 8080

# Run the application
ENTRYPOINT ["java", "-jar", "./elephant.jar", "-Duser.timezone=GMT+08"]
